<template>
  <view class="orderSubmit">
    <view class="order_address">
      <view class="address_left_box">
        <view class="address_icon">
          <image src="../../static/images/icon/icon_gps1.png" mode=""></image>
        </view>
        <view class="address_info_box" v-if="curAddress.id">
          <view class="address_name">
            {{curAddress.province}}
            {{curAddress.city}}
            {{curAddress.county}}
            {{curAddress.address}}
            <span v-if="curAddress.num"> {{curAddress.num}}</span>
          </view>
          <view class="address_info_desc">
            {{curAddress.fullname}}
            {{curAddress.phone}}
          </view>
        </view>
        <view v-else>
          请添加地址
        </view>
      </view>
      <view class="address_right_btn" @tap="goAddress">
        <image src="../../static/images/icon/icon_moer_btn.png" mode=""></image>
      </view>
    </view>
    <view class="order_desc_list">
      <view class="order_decs_line_box">
        <view class="order_decs_line_left_box">
          <view class="order_decs_title_box">
            土地类型
          </view>
          <view class="order_decs_content_box">
            {{resData.option.area}}㎡{{resData.option.option_name}}
          </view>
        </view>
        <view class="order_decs_line_right_box">
          ￥{{resData.product_price}}
        </view>
      </view>
      <view class="order_decs_line_box">
        <view class="order_decs_line_left_box">
          <view class="order_decs_title_box">
            租赁时长
          </view>
          <view class="order_decs_content_box">
            <span v-if="resData.day_type=='year'">一年(365天)</span>
            <span v-else>半年(180天)</span>
          </view>
        </view>
        <view class="order_decs_line_right_box">
          <!-- ￥399.00 -->
        </view>
      </view>
      <view class="order_decs_line_box">
        <view class="order_decs_line_left_box">
          <view class="order_decs_title_box">
            服务类型
          </view>
          <view class="order_decs_content_box">
            <span
              v-if="resData.day_type=='year'&&resData.service_type!='own'">{{serviceType[resData.service_type]}}（￥{{Number(resData.service_price)/365}}/天）</span>
            <span
              v-if="resData.day_type=='half_year'&&resData.service_type!='own'">{{serviceType[resData.service_type]}}（（￥{{Number(resData.service_price)/180}}/天）</span>
            <span v-if="resData.service_type=='own'">{{serviceType[resData.service_type]}}</span>
          </view>
        </view>
        <view class="order_decs_line_right_box">
          ￥{{resData.service_price}}
        </view>
      </view>
      <view class="order_decs_line_seed_box">
        <view class="order_decs_title_box">
          种子选择
        </view>
        <view class="order_seed_decs_content_box">
          <view v-for="item in resData.select_seed">
            <view class="seed_sku_box">
              <view class="seed_name">
                {{item.name}}X{{item.num}}
              </view>
              <view class="seed_price">
                {{item.total_price}}
              </view>
            </view>
          </view>
        </view>
      </view>
      <view class="order_total_box">
        合计: ￥{{resData.total_price}}
      </view>
    </view>
    <view class="bottom_op_box">
      <button class="buy_now" @tap="buyNow">订单提交</button>
    </view>
  </view>
</template>

<script>
export default {
  data () {
    return {
      params: {

      },
      resData: {},
      serviceType: {
        own: '自行种植',
        all: '全包',
        half: '半包'
      },
      curAddress: {}
    };
  },
  onLoad (val) {
    if (val.params) {
      this.params = JSON.parse(val.params);
      this.resData = JSON.parse(val.resData);
      console.log(this.resData, 'agaga');
      this.$api.getMyAddress().then(res => {
        if (res.code == 1) {
          console.log(res, '当前获取地址');
          this.setAddress(res.data.lists[0]);
        }
      })
    }
  },
  methods: {
    buyNow () {
      this.$api.createGroOrder(this.params).then(res => {
        if (res.code == 1) {
          uni.navigateTo({
            url: `/pages/groundPage/payPage?resData=${JSON.stringify(res.data)}`
          })
        } else {
          this.$helper.toast(res.msg);
        }
      })
    },
    goAddress () {
      uni.navigateTo({
        url: '/pages/integralShop/intergralAddress?pageType=order'
      });
    },
    setAddress (address) {
      this.curAddress = address;
      this.params.address_id = address.id;
      console.log(this.curAddress, '当前选择地址');
    },
  },
  computed: {

  }
}
</script>

<style lang="scss">
.orderSubmit {
  padding: 20rpx 24rpx;
  min-height: 100vh;
  background-color: #f9f9f9;

  .order_address {
    background: #ffffff;
    border-radius: 20rpx;
    padding: 33rpx 15rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30rpx;

    .address_left_box {
      display: flex;
      align-items: center;

      .address_icon {
        width: 32rpx;
        height: 39rpx;
        margin-right: 20rpx;
        flex: none;
        image {
          width: 100%;
          height: 100%;
        }
      }

      .address_info_box {
        .address_name {
          font-weight: 500;
          font-size: 34rpx;
          color: #333333;
          margin-bottom: 6rpx;
        }

        .address_info_desc {
          font-size: 28rpx;
          color: #999999;
        }
      }
    }

    .address_right_btn {
      width: 38rpx;
      height: 38rpx;
      flex: none;

      image {
        width: 100%;
        height: 100%;
      }
    }
  }

  .order_desc_list {
    background: #ffffff;
    border-radius: 20rpx;
    padding: 28rpx 23rpx;

    .order_decs_line_box {
      display: flex;
      justify-content: space-between;
      margin-bottom: 37rpx;

      .order_decs_line_left_box {
        display: flex;

        .order_decs_title_box {
          font-weight: 400;
          font-size: 28rpx;
          color: #999999;
          margin-right: 20rpx;
        }

        .order_decs_content_box {
          font-size: 28rpx;
          color: #333333;
        }
      }

      .order_decs_line_right_box {
        font-size: 28rpx;
        color: #333333;
      }
    }

    .order_decs_line_seed_box {
      display: flex;
      margin-bottom: 20rpx;

      .order_decs_title_box {
        font-weight: 400;
        font-size: 28rpx;
        color: #999999;
        margin-right: 20rpx;
        flex: none;
      }

      .order_seed_decs_content_box {
        font-size: 28rpx;
        color: #333333;
        flex: 1;

        .seed_sku_box {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-bottom: 6rpx;
        }
      }
    }

    .order_total_box {
      text-align: right;
      font-size: 28rpx;
      color: #333333;
    }
  }
}

.bottom_op_box {
  display: flex;
  position: relative;
  width: 100vw;
  align-items: center;
  background: #ffffff;
  justify-content: space-between;
  padding: 19rpx 23rpx;
  position: fixed;
  box-sizing: border-box;
  bottom: 0;
  left: 0;

  .buy_now {
    width: 96%;
    height: 80rpx;
    background: #fed100;
    border-radius: 40rpx;
    font-size: 30rpx;
  }
}
</style>